<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
      
    <div>
        <label for="">用户名</label>
        <input type="text" id="username">
     </div>
     <div>
        <label for="">密码</label>
        <input type="text" id="password">
     </div>
     <div>
        <button>   登录</button>
     </div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.2/jquery.js"></script>
<script>
    $("button").click(()=>{
        let username = $("#username").val();
        let password = $("#password").val();
        $.ajax({
            url:"/user/login",
            method:"post",
            data:{
                username,
                password
            },
            success(res){
                console.log(res)
                if(res.code==0){
                    // 获取后端返回的token
                    let token = res.data.token;
                    // 将token存储到本地
                    localStorage.setItem("LOGIN_TOKEN",token)
                    window.location.href = './index.html'
                }
                // 
            }
        })
    })
</script>
</html>